<?php

class StringUtil {
	
	public static function startsWith($haystack, $needle) {
		$length = strlen($needle);
		return (substr($haystack, 0, $length) === $needle);
	}

	public static function endsWith($haystack, $needle) {
		$length = strlen($needle);
		if ($length == 0) {
			return true;
		}

		return (substr($haystack, -$length) === $needle);
	}
	
	public static function getConnectionString($connectionString, $driverName, $username, $password) {		
        list($host, $dbname) = explode(';', Yii::app()->db->connectionString);
        list(, $host) = explode('=', $host);
        list(, $dbname) = explode('=', $dbname);
        return "{$driverName}://$username:$password@$host/$dbname";
	}
}